package cn.edu.scau.cmi.zhangmingxing.comprehensiveClient;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class ComprehensiveController {

	@FXML
	private Button HibernateButton;

	@FXML
	private Button SingletonButton;

	@FXML
	private Button AbstractFactoryButton;

	@FXML
	private Button SimpleFactoryMethodButton;

	@FXML
	private Button ConsistentCompositeButton;

	@FXML
	private ImageView imageView;

	@FXML
	private Button AdapterButton;

	@FXML
	private Button SpringButton;

	@FXML
	private Button SafeCompositeButton;

	@FXML
	private Button FactoryButton;

	@FXML
	private Button InterProgrammingButton;

	public void begin(Parent root, Stage primaryStage) {
		imageView.setImage(new Image("file:client/cn/edu/scau/cmi/zhangmingxing/comprehensiveClient/image.jpg"));
		primaryStage.setTitle("综合性实验");
		Scene scene = new Scene(root);
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	@FXML
	void SingletonAction(ActionEvent event) throws NoSuchMethodException, SecurityException, ClassNotFoundException,
			InstantiationException, IllegalAccessException {

		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.SingletonClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});

	}

	@FXML
	void InterProgrammingAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException,
			SecurityException, InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.InterProgrammingClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void SimpleFactoryMethodAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException,
			SecurityException, InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.SimpleFactoryMethodClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void FactoryAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
			InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.FactoryClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void AbstractFactoryAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException,
			SecurityException, InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.AbstractFactoryClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void AdapterAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
			InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.AdapterClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void ConsistentCompositeAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException,
			SecurityException, InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.ConsistentCompositeClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void SafeCompositeAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
			InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.client.SafeCompositeClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void HibernateAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
	InstantiationException, IllegalAccessException{
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.framework.client.HibernateClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}

	@FXML
	void SpringAction(ActionEvent event) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
	InstantiationException, IllegalAccessException{
		Class clazz = Class.forName("cn.edu.scau.cmi.zhangmingxing.framework.client.SpringClient");
		Method start = clazz.getMethod("start", Stage.class);
		Object object = clazz.newInstance();
		Platform.runLater(() -> {
			try {
				start.invoke(object, (Object) new Stage());
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} catch (IllegalArgumentException e) {

				e.printStackTrace();
			} catch (InvocationTargetException e) {

				e.printStackTrace();
			}
		});
	}
}
